/*
 * @Description: 关注表
 * @Author: Junhuang
 * @Date: 2022-02-22 14:50:24
 * @LastEditTime: 2022-02-22 15:04:37
 * @LastEditors: Junhuang
 * @Reference: 
 */
'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const { INTEGER, STRING, DATE, ENUM, TEXT } = Sequelize;
    // 创建表
    await queryInterface.createTable('follow', {
      id: {
        type: INTEGER(20), primaryKey: true, autoIncrement: true, comment: '主键id'
      },
      // 发起关注的用户id
      user_id: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '发起专注的用户id',
        references: {
          model: 'user',
          key: 'id'
        },
        onDelete: 'cascade',
        onUpdate: 'restrict', // 更新时操作
      },
      follow_user_id: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '被关注的用户id',
        references: {
          model: 'user',
          key: 'id'
        },
        onDelete: 'cascade',
        onUpdate: 'restrict', // 更新时操作
      },
      created_time: DATE,
      updated_time: DATE
    });
  },

  async down(queryInterface, Sequelize) {
    return queryInterface.dropTable('follow');
  }
};
